﻿using System;
using System.Drawing;
using UnityEditor.VersionControl;
using UnityEngine;

namespace GameCore
{




    /// <summary>
    /// 日志类型
    /// </summary>
    public enum LogType
    {
        /// <summary>
        ///  一般log打印
        /// </summary>
        Log,
        /// <summary>
        ///  重要信息打印
        /// </summary>
        Info,
        /// <summary>
        /// 警告提示打印
        /// </summary>
        Warning,
        /// <summary>
        ///  一般错误打印
        /// </summary>
        Error,
        /// <summary>
        ///  严重错误打印
        /// </summary>
        SeriousError,
    }

    /// <summary>
    /// 日志打印工具
    /// </summary>
    public static class LogUtils
    {
        /// <summary>
        /// 日志是否激活
        /// </summary>
        public static bool IsActive
        {
            get
            {
                return Debug.unityLogger.logEnabled;
            }

            set
            {                
                Debug.unityLogger.logEnabled = value;
            }
        }
        /// <summary>
        /// 一般log打印
        /// </summary>
        /// <param name="message">内容</param>
        public static void Log(object message)
        {
            if (!IsActive)
                return;
            Logger(LogType.Log, message);
        }
        /// <summary>
        /// 一般log打印
        /// </summary>
        /// <param name="format">格式</param>
        /// <param name="args">参数</param>
        public static void Log(string format, params object[] args)
        {
            if (!IsActive)
                return;
            string message = string.Format(format, args);
            Logger(LogType.Log, message);
        }
        /// <summary>
        /// 重要信息打印
        /// </summary>
        /// <param name="message">内容</param>
        public static void Info(object message)
        {
            if (!IsActive)
                return;
            Logger(LogType.Info, message);
        }
        /// <summary>
        /// 重要信息打印
        /// </summary>
        /// <param name="format">格式</param>
        /// <param name="args">参数</param>
        public static void Info(string format, params object[] args)
        {
            if (!IsActive)
                return;
            string message = string.Format(format, args);
            Logger(LogType.Info, message);
        }
        /// <summary>
        /// 警告提示打印
        /// </summary>
        /// <param name="message">内容</param>
        public static void Warning(object message)
        {
            if (!IsActive)
                return;
            Logger(LogType.Warning, message);
        }
        /// <summary>
        /// 警告提示打印
        /// </summary>
        /// <param name="format">格式</param>
        /// <param name="args">参数</param>
        public static void Warning(string format, params object[] args)
        {
            if (!IsActive)
                return;
            string message = string.Format(format, args);
            Logger(LogType.Warning, message);
        }
        /// <summary>
        /// 一般错误打印
        /// </summary>
        /// <param name="message">内容</param>
        public static void Error(object message)
        {
            if (!IsActive)
                return;
            Logger(LogType.Error, message);
        }
        /// <summary>
        /// 一般错误打印
        /// </summary>
        /// <param name="format">格式</param>
        /// <param name="args">参数</param>
        public static void Error(string format, params object[] args)
        {
            if (!IsActive)
                return;
            string message = string.Format(format, args);
            Logger(LogType.Error, message);
        }
        /// <summary>
        /// 严重错误
        /// </summary>
        /// <param name="message">内容</param>
        public static void SeriousError(object message)
        {
            if (!IsActive)
                return;
            Logger(LogType.SeriousError, message);
        }
        /// <summary>
        /// 严重错误
        /// </summary>
        /// <param name="format">格式</param>
        /// <param name="args">参数</param>
        public static void SeriousError(string format, params object[] args)
        {
            if (!IsActive)
                return;
            string message = string.Format(format, args);
            Logger(LogType.SeriousError, message);
        }

        /// <summary>
        /// log打印
        /// </summary>
        /// <param name="type">类型</param>
        /// <param name="message">内容</param>
        private  static void Logger(LogType type, object message) 
        {
            switch (type) 
            { 
                case LogType.Log:
                    Debug.Log(string.Format("[Log]:{0}",message));
                    break; 
                case LogType.Info:
                    Debug.Log(string.Format("[<color=#33B1B0>Info</color>]:<color=#33B1B0>{0}</color>", message));
                    break; 
                case LogType.Warning:
                    Debug.LogWarning(string.Format("[Warning]:<color=#33B1B0>{0}</color>", message));
                    break; 
                case LogType.Error:
                    Debug.LogError(string.Format("[Error]:{0}", message));
                    break;
                case LogType.SeriousError:
                    Debug.LogError(string.Format("[<color=#865FC5>SeriousError</color>]:{0}", message));
                    break;

            }

        }
    }
}